
import { Request } from '../utils/request';
import md5 from 'js-md5';

/**
 * 注册账号
 * @param email 邮箱
 * @param username 用户名
 * @param password 密码
 * @param verifyCode 邮箱验证码
 * @returns
 */
export function register(email: string, username: string, password: string, verifyCode: string) {
  return Request.axiosInstance({
    url: '/user/register',
    method: 'post',
    data: { email, username, password: md5(password), verifyCode }
  })
}

/**
 * 用户登录
 * @param id 用户名/邮箱
 * @param password 密码
 * @returns
 */
export function login(id: string, password: string) {
  return Request.axiosInstance({
    url: '/user/login',
    method: 'post',
    data: { id, password: md5(password) }
  })
}

/**
 * 修改密码
 * @param email 邮箱
 * @param newPassword 新密码
 * @param verifyCode 验证码
 * @returns
 */
export function modifyPassword(email: string, newPassword: string, verifyCode: string) {
  return Request.axiosInstance({
    url: '/user/modify_password',
    method: 'post',
    data: { email, newPassword: md5(newPassword), verifyCode }
  })
}

/**
 * 修改头像
 * @param formData profileLink
 * @returns
 */
export function modifyProfile(formData: FormData) {
  return Request.axiosInstance({
    url: '/user/modify_profile',
    method: 'post',
    data: formData,
    headers: {
      'Content-Type': 'multipart/form-data'
    }
  })
}

/**
 * 获取用户个人信息
 * @returns
 */
export function getUserInfo() {
  return Request.axiosInstance({
    url: '/user/info',
    method: 'get'
  })
}

/**
 * 获取用户统计数据
 * @returns
 */
export function getUserStatistic() {
  return Request.axiosInstance({
    url: '/user/statistic',
    method: 'get'
  })
}

